<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
    protected override void OnLoad(EventArgs e)
    {
        if (string.IsNullOrEmpty(Request["DocID"])||Request["DocID"].ToString().Length!=36)
        {
            Response.Write("<script type=\"text/javascript\">window.close();<" + "/script>");
            return;
        }
        string[] strArr = BLF.WWW_WWW.Files.Files.UpdateDownLoad(Request["DocID"]);
        string ct = "", file = "";
        if (strArr != null && strArr.Length==2)
        {
            file = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["UploadFileFolader"] + "/"+strArr[0]);
            ct = strArr[1];
        }
        else
        {
            Response.Write("<script>window.close();<"+"/script>");
            return;
        }
        if(ct!=""&&file!="")
        {
            if (System.IO.File.Exists(file))
            {
                FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
                Byte[] by = new Byte[fs.Length];
                Response.Buffer = true;
                Response.HeaderEncoding = Encoding.UTF8;
                Response.ContentType = ct;
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + file);
                HttpContext.Current.Response.AddHeader("Content-Length", fs.Length.ToString());
                if (fs.CanRead)
                {
                    fs.Read(by, 0, by.Length);
                }
                fs.Close();
                Response.Clear();
                Response.BinaryWrite(by);
                Response.Flush();
                return;
            }
            else
            {
                Response.Write("<script>window.close();<" + "/script>");
                return;
            }
        }
        else
        {
            Response.Write("<script>window.close();<" + "/script>");
            return;
        }
    }
</script>